<template>
  <BaseMainSlot>
    <template v-slot:content>
      <e-table
        ref="tableData"
        :table-data="tableData"
        :table-columns="tableLabel"
        :page="currentPage"
        :size="pageSize"
        :total="totalSize"
        :loading="loading"
        :showSelectColumn="false"
        :table-option="tableOption"
        @sizeChange="changePageSize"
        @pageChange="changeCurrentPage"
      >
        <template slot="operate" slot-scope="scoped" v-if="scoped.row.sort">
          <span>
            <span
              class="table-btns-box"
              v-if="!scoped.row.audit&&judgePermission(148,'start')"
              @click="start(scoped.row)"
            >
              <i class="el-icon-open"></i>
              <span>启用</span>
            </span>
            <span
              class="table-btns-box"
              v-if="scoped.row.audit&&judgePermission(148,'stop')"
              @click="stop(scoped.row)"
            >
              <i class="el-icon-turn-off"></i>
              <span>停用</span>
            </span>
            <span
              class="table-btns-box"
              v-if="judgePermission(148,'edit')"
              @click="edit(scoped.row)"
            >
              <i class="el-icon-edit-outline"></i>
              <span>修改</span>
            </span>
          </span>
        </template>
      </e-table>

      <AddEditDialog
        ref="addEditDialog"
        :now-chance-stau="nowChanceStau"
        :title-text="titleText"
        :edit-object="editObject"
        :show.sync="showAddEditDialog"
        @closeDialog="closeDialog"
        @cancelDialog="cancel"
      />
    </template>
  </BaseMainSlot>
</template>

<script>
import nodeConfigApi from "@/api/equip-repair-manage/node-config";
import BaseMainSlot from "@/components/BaseMainSlot/kong-new.vue";
import AddEditDialog from "./components/add-edit-dialog.vue";
import { mymixin } from "@/utils/mixin";
import { mapGetters } from "vuex";

export default {
  name: "RepairType",
  components: { BaseMainSlot, AddEditDialog },
  mixins: [mymixin],
  data() {
    return {
      // 所搜条件：类型名称
      groupName: "",
      // checkedIdList: [],
      // 表单展示项
      tableLabel: [
        {
          label: "维修节点名称",
          param: "groupName",
          show: true,
          notSearch: true,
        },
        {
          label: "负责人",
          param: "auditor",
          show: true,
          notSearch: true,
        },
      ],

      // 表单事件
      tableOption: {
        label: "操作",
        options: [
          {
            label: "操作",
            type: "text",
            icon: "el-icon-edit-outline",
            methods: "operate",
            slotName: "operate",
          },
        ],
      },
    };
  },
  computed: {
    ...mapGetters({
      judgePermission: "permission/judgePermission",
    }),
  },
  watch: {},
  created() {
    this.queryPageList();
  },
  mounted() {},
  methods: {
    queryPageList() {
      this.loading = false;
      nodeConfigApi.query({}).then((res) => {
        this.loading = false;
        if (res.code === 1) {
          let data = res.data;
          this.totalSize = data.length;
          this.tableData = data;
          this.addblankmet();
          this.resetActionBar();
        }
      });
    },

    // 修改
    edit(row) {
      if (row.sort) {
        this.editObject = JSON.parse(JSON.stringify(row));
        this.nowChanceStau = "edit";
        this.titleText = "修改";
        this.addActive = false;
        this.delActive = false;
        this.showAddEditDialog = true;
      } else {
        this.editObject = {};
      }
    },
    // 启用
    start(data) {
      this.$confirm("确认启用该节点?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        customClass: "myClass",
      })
        .then(() => {
          var form = {
            audit: true,
            auditor: data.auditor,
            repairNodeName: data.repairNodeName,
            jumpNode: data.jumpNode,
            groupName: data.groupName,
            sort: data.sort,
            repairNodeId: data.repairNodeId,
            organizationMark: sessionStorage.organizationNo,
          };
          nodeConfigApi.edit(form).then((res) => {
            if (res.code === 1) {
              this.$message.success(res.msg);
              this.queryPageList();
              this.resetActionBar();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 停用
    stop(data) {
      this.$confirm("确认停用该节点?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        customClass: "myClass",
      })
        .then(() => {
          var form = {
            audit: false,
            auditor: data.auditor,
            repairNodeName: data.repairNodeName,
            jumpNode: data.jumpNode,
            groupName: data.groupName,
            sort: data.sort,
            repairNodeId: data.repairNodeId,
            organizationMark: sessionStorage.organizationNo,
          };
          nodeConfigApi.edit(form).then((res) => {
            if (res.code === 1) {
              this.$message.success(res.msg);
              this.queryPageList();
              this.resetActionBar();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // selectAll(list) {
    //   let notvalue = true
    //   let notvalue1 = true
    //   list.forEach(item => {
    //     var index = this.noDelList.findIndex(a => a === item.jumpNode)
    //     if (index === -1) {
    //       if (!item.jumpNode) {
    //         notvalue = false
    //       }
    //     } else {
    //       notvalue1 = false
    //     }
    //   });
    //   if (notvalue === false && notvalue1 === true) {
    //     this.$message.warning("不可选择空数据！");
    //   } else if (notvalue1 === false && notvalue === true) {
    //     this.$message.warning("类型已被使用，请勿删除！");
    //   } else if (notvalue1 === false && notvalue === false) {
    //     this.$message.warning("类型已被使用，请勿删除！，不可选择空数据！");
    //   }
    // },
    // select(list) {
    //   let notvalue = true
    //   let notvalue1 = true
    //   list.forEach(item => {
    //     var index = this.noDelList.findIndex(a => a === item.jumpNode)
    //     if (index === -1) {
    //       if (!item.jumpNode) {
    //         notvalue = false
    //       }
    //     } else {
    //       notvalue1 = false
    //     }
    //   });
    //   if (notvalue === false && notvalue1 === true) {
    //     this.$message.warning("不可选择空数据！");
    //   } else if (notvalue1 === false && notvalue === true) {
    //     this.$message.warning("类型已被使用，请勿删除！");
    //   } else if (notvalue1 === false && notvalue === false) {
    //     this.$message.warning("类型已被使用，请勿删除！，不可选择空数据！");
    //   }
    // },
    // handleSelectionChange(list) {
    //   this.checkedIdList = [];
    //   let notvalue = true
    //   let emptyList = []
    //   this.checkedIdList = list.map(item => {
    //     var index = this.noDelList.findIndex(a => a === item.jumpNode)
    //     if (index === -1) {
    //       if (item.jumpNode) {
    //         return item.jumpNode
    //       } else {
    //         notvalue = false
    //         emptyList.push(item)
    //         return ""
    //       }
    //     } else {
    //       // this.$message.warning("该辖区已被绑定，若想删除，请先解绑！");
    //       this.toggleNoSelection([item])
    //       return
    //     }
    //   });
    //   if (notvalue === false) {
    //     // this.$message.warning("不可选择空数据！");
    //     this.toggleNoSelection(emptyList)
    //     return
    //   }
    //   if (this.checkedIdList.length >= 1) this.delActive = true;
    //   else this.delActive = false;
    // },

    // // 单个删除
    // delOne(data) {
    //   var index = this.noDelList.findIndex(a => a === data.jumpNode)
    //   if (index === -1) {
    //     this.$confirm("此操作将永久删除该项, 是否继续?", "提示", {
    //       confirmButtonText: "确定",
    //       cancelButtonText: "取消",
    //       type: "warning",
    //       customClass: "myClass"
    //     })
    //       .then(() => {
    //         var form = new FormData()
    //         form.append('jumpNodeList', data.jumpNode)
    //         repairTypeApi.delList(form).then(res => {
    //           if (res.code === 1) {
    //             this.$message.success(res.msg);
    //             this.queryPageList();
    //             this.resetActionBar();
    //           }
    //         });
    //       })
    //       .catch(() => {
    //         this.$message({
    //           type: "info",
    //           message: "已取消删除"
    //         });
    //       });
    //   }
    // },
    // // 表格删除
    // delmessage() {
    //   var form = new FormData()
    //   this.checkedIdList.forEach(a => {
    //     form.append('jumpNodeList', a)
    //   })
    //   repairTypeApi.delList(form).then(res => {
    //     if (res.code === 1) {
    //       this.$message.success(res.msg);
    //       this.queryPageList();
    //       this.resetActionBar();
    //     }
    //   });
    // },
    // // 添加
    // add() {
    //   this.nowChanceStau = 'add'
    //   this.titleText = "添加"
    //   this.addActive = false;
    //   this.delActive = false;
    //   this.editActive = false;
    //   this.showAddEditDialog = true
    // },
    // // 修改
    // edit(row) {
    //   if (row.jumpNode) {
    //     this.editObject = JSON.parse(JSON.stringify(row));
    //     this.nowChanceStau = 'edit'
    //     this.titleText = "修改"
    //     this.addActive = false;
    //     this.delActive = false;
    //     this.showAddEditDialog = true
    //   } else {
    //     this.editObject = {};
    //   }
    // }
  },
};
</script>

<style lang="scss" scoped>
</style>
